//
//  HotTopicScrollView.m
//  FlowerRainGround
//
//  Created by lanou on 16/4/25.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "HotTopicScrollView.h"
#import "TopicModel.h"


@interface HotTopicScrollView ()<UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView *hotTopicScrollView;
@property (nonatomic, strong) NSMutableArray *hotTopicArray;

@end

@implementation HotTopicScrollView

- (NSMutableArray *)hotTopicArray {
    if (!_hotTopicArray) {
        self.hotTopicArray = [NSMutableArray array];
    }
    return _hotTopicArray;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
    }
    return self;
}

- (void) createScrollViewWithHotTopicArray:(NSMutableArray *)hotTopicArray {
    
    self.hotTopicArray = hotTopicArray;
    self.autoresizesSubviews = YES; // 设置子视图自动布局
    CGFloat imageHeight = self.frame.size.height;
    self.hotTopicScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kWidth, imageHeight)];
    
    self.hotTopicScrollView.backgroundColor = [UIColor clearColor];
    self.hotTopicScrollView.contentSize = CGSizeMake(imageHeight * 5, imageHeight);
    self.hotTopicScrollView.bounces = NO;
    self.hotTopicScrollView.pagingEnabled = NO;
    self.hotTopicScrollView.showsHorizontalScrollIndicator = NO;
    
    
    for (int i = 0; i < 5; i ++) {
        
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i * imageHeight, 0, imageHeight, imageHeight)];
        imageView.userInteractionEnabled = YES;
        
        //  添加单击手势
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(imageViewTapAction:)];
        [imageView addGestureRecognizer:tapGesture];
        
        //        NSLog(@"...%@",self.hotTopicArray);
        TopicModel *model = self.hotTopicArray[i];
        [imageView sd_setImageWithURL:[NSURL URLWithString:model.ico]];
        
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, imageHeight - 20, imageHeight, 20)];
        label.text = [NSString stringWithFormat:@"#%@#",model.name];
        label.alpha = 0.4;
        label.textAlignment = 1;
        label.backgroundColor = [UIColor orangeColor];
        [imageView addSubview:label];
        imageView.tag = 3000+i;
        
        [self.hotTopicScrollView addSubview:imageView];
    }
    
    [self addSubview:self.hotTopicScrollView];
    
}

- (void)imageViewTapAction:(UITapGestureRecognizer *)tap {
    UIImageView *imageView = (UIImageView *)tap.view;
    if (self.TapActionBlock) {
        
        self.TapActionBlock(imageView);
    }
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
